/******************************************************************************
* bankruptcy attorney fees from the consumer bankruptcy fee study, Lois Lupica
*****************************************************************************/


clear all
set more off
global proj "/Users/hanyang/tu2"
global dataRoot "${proj}/Data"



** fee data
use $dataRoot/Raw/bankrupt_legal_fee.dta, clear


** cw to county and then cz
merge 1:m district using "$dataRoot/Crosswalk/cw_cty_courtdistrict.dta"
keep if _merge==3
drop _merge

rename county district_county

*cross walk county to cz
rename countyfips county_id
merge m:1 county_id using "$dataRoot/Crosswalk/cw_cty00_cz.dta"
keep if _merge==3
drop _merge


*merge to cz
collapse *fee* [w=pop2000], by(cz czname state_id stateabbrv) fast


rename dismissedchp13feepre  chp13feepre_dis
rename dismissedchp13feepost chp13feepost_dis


label var chp13feepre  		"chapter 13 attorney fee pre BAPCPA"
label var chp13feepost 		"chapter 13 attorney fee post BAPCPA"
label var chp13feepre_dis   "dismissed chapter 13 attorney fee pre BAPCPA"
label var chp13feepost_dis  "dismissed chapter 13 attorney fee post BAPCPA"
label var chp7feepre  		"chapter 7 attorney fee pre BAPCPA"
label var chp7feepost 		"chapter 7 attorney fee post BAPCPA"

foreach var of varlist chp*fee*{
	replace `var' = `var'/1000
}

	
***  Save cz level bankruptcy legal fee data
compress
save "$dataRoot/Clean/TU_bankruptcy_fee", replace
